//
//  StatusDetailBottomToolBar.m
//  Weibo
//
//  Created by Anasue on 10/2/15.
//  Copyright © 2015 vvusu. All rights reserved.
//

#import "StatusDetailBottomToolBar.h"

@interface StatusDetailBottomToolBar ()

@end

@implementation StatusDetailBottomToolBar

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupBtnWithIcon:@"timeline_icon_retweet" title:@"转发"];
        [self setupBtnWithIcon:@"timeline_icon_comment" title:@"评论"];
        [self setupBtnWithIcon:@"timeline_icon_unlike" title:@"赞"];
    }
    return self;
}
/**
 *  增加按钮
 *
 */
- (UIButton *)setupBtnWithIcon:(NSString *)icon title:(NSString *)title
{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageWithName:icon] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:btn];
    return btn;
}

/**
 *  按钮的位置
 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //按钮位置
    CGFloat margin = 10;
    NSInteger count = self.subviews.count;
    CGFloat btnW = (self.width - (count + 1) * margin)/ count;
    CGFloat btnY = 5;
    CGFloat btnH = self.height - 2 * btnY;
    for (int i = 0; i < count; i ++) {
        UIButton *btn = self.subviews[i];
        btn.x = i * (btnW + margin) + margin;
        btn.y = btnY;
        btn.width = btnW;
        btn.height = btnH;
    }
    
}

- (void)drawRect:(CGRect)rect
{
    [[UIImage resizeImage:@"statusdetail_toolbar_background"]drawInRect:rect];
}


@end
